#include "mainscene.h"
#include "ui_mainscene.h"
#include<QPainter>
#include"mypushbutton.h"
#include<QTimer>
#include<QSoundEffect>
MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);
    //配置主场景

    //设置固定大小
    setFixedSize(320,588);
    //设置图标
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    //设置标题
    setWindowTitle("翻金币");
    //退出游戏操作
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });
    //游戏音效
    QSoundEffect *startSound=new QSoundEffect();

    //开始按钮
    MyPushButton *startBtn=new MyPushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);
    //实例化选择关卡场景
    chooseScene=new chooselevelscene;
    connect(chooseScene,&chooselevelscene::chooseCloseScene,[=](){
        chooseScene->hide();
        this->show();
    });
    connect(startBtn,&MyPushButton::clicked,[=](){
        startSound->setSource(QUrl::fromLocalFile(":/res/TapButtonSound.wav"));
        startSound->play();
        startBtn->zoom1();
        startBtn->zoom2();
        //设置延时
        QTimer::singleShot(500,this,[=](){
            //进入到选择关卡场景中
            //自身隐藏
            //显示选择关卡场景
            this->hide();
            chooseScene->show();

        });
    });


}
//绘制主页面
void MainScene::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/background.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
    //画图标
    pix.load(":/res/Title.png");
    pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix);
}
MainScene::~MainScene()
{
    delete ui;
}
